/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action.news;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import myUtils.Utils;
import org.apache.struts2.interceptor.ServletRequestAware;
import po.News;
import po.User;
import service.NewsService;

/**
 *
 * @author sony
 */
public class showNewsDetailAction extends ActionSupport implements ServletRequestAware {

    private HttpServletRequest request;
    private NewsService newsService;
    private News news;
    private boolean isAuthor;

    @Override
    public String execute() 
    {
        /*Cookie[] cookie=request.getCookies();
        for(int i=0;i<cookie.length;++i)
            System.out.println(cookie[i].getName() + " ==> "+cookie[i].getValue());*/

        Utils.getPreURL(request);

        int id = Integer.valueOf(request.getParameter("id"));
        news = newsService.getNews(id);
        if (ActionContext.getContext().getSession().get("user") != null) {
            int userId = ((User) ActionContext.getContext().getSession().get("user")).getId();
            isAuthor = newsService.isAuthor(id, userId);
            if(((User) ActionContext.getContext().getSession().get("user")).getType()==1)isAuthor=true;
        } else {
            isAuthor = false;
        }

        return SUCCESS;
    }

    public NewsService getNewsService() {
        return newsService;
    }

    public void setNewsService(NewsService newsService) {
        this.newsService = newsService;
    }

    public void setServletRequest(HttpServletRequest arg0) {
        this.request = arg0;
    }

    public News getNews() {
        return news;
    }

    public void setNews(News news) {
        this.news = news;
    }

    public boolean isIsAuthor() {
        return isAuthor;
    }

    public void setIsAuthor(boolean isAuthor) {
        this.isAuthor = isAuthor;
    }
}
